﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace RefOffPDA
{
    /*
     * Class: Caution
     * 
     * Use: Used to indicate which player is receiving
     *      a caution
     *      
     * Author: Mike Skaife, mcs3@aber.ac.uk
     */ 
    public partial class Caution : Form
    {
        //The current Match object
        Match theMatch;

        //Indicate whether the home or away
        //team is receiving the caution
        String homeOrAway;

        //id of the player being cautioned
        int player_id;
                
        public Caution(Match match, String homeAway)
        {
            InitializeComponent();
            theMatch = match;
            homeOrAway = homeAway;
        }

        //This method is called when a player button is clicked
        private void cautionPlayer()
        {
            //Set variables in Caution Code screen to
            //indicate player and team involved
            theMatch.cautionCode.player_id = player_id;
            theMatch.cautionCode.homeOrAway = homeOrAway;

            //Hide this screen and display the Caution Code screen
            theMatch.cautionCode.Visible = true;
            this.Visible = false;
        }        

        //This method is run when the first player in the list is being cautioned
        private void CautionPlayer1Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer1Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer1Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer1Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer1Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer1Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer1Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer1Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer1Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer1Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the second player in the list is being cautioned
        private void CautionPlayer2Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer2Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer2Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer2Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer2Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer2Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer2Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer2Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer2Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer2Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the third player in the list is being cautioned
        private void CautionPlayer3Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer3Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer3Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer3Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer3Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer3Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer3Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer3Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer3Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer3Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the fourth player in the list is being cautioned
        private void CautionPlayer4Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer4Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer4Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer4Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer4Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer4Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer4Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer4Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer4Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer4Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the fifth player in the list is being cautioned
        private void CautionPlayer5Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer5Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer5Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer5Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer5Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer5Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer5Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer5Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer5Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer5Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the sixth player in the list is being cautioned
        private void CautionPlayer6Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer6Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer6Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer6Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer6Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer6Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer6Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer6Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer6Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer6Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the seventh player in the list is being cautioned
        private void CautionPlayer7Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer7Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer7Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer7Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer7Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer7Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer7Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer7Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer7Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer7Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the eighth player in the list is being cautioned
        private void CautionPlayer8Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer8Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer8Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer8Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer8Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer8Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer8Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer8Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer8Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer8Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the ninth player in the list is being cautioned
        private void CautionPlayer9Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer9Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer9Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer9Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer9Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer9Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer9Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer9Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer9Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer9Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the tenth player in the list is being cautioned
        private void CautionPlayer10Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer10Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer10Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer10Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer10Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer10Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer10Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer10Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer10Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer10Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the eleventh player in the list is being cautioned
        private void CautionPlayer11Btn_Click(object sender, EventArgs e)
        {
            //Obtain the id of the player being cautioned, from the
            //button that was clicked
            player_id = Int32.Parse(CautionPlayer11Btn.Tag.ToString());

            //This code runs if the home team is receiving the caution
            if (homeOrAway.Equals("home"))
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer11Btn;
                theMatch.cautionCode.goalButton = theMatch.homeGoal.GoalPlayer11Btn;
                theMatch.cautionCode.sendOffButton = theMatch.homeSendOff.SendOffPlayer11Btn;
                theMatch.cautionCode.subOffButton = theMatch.homeSubOff.SubOffPlayer11Btn;
            }
            //This code runs if the away team is receiving the caution
            else
            {
                //Indicate in the Caution Code screen, which buttons from
                //other screens need to be updated as a result of the caution
                theMatch.cautionCode.cautionButton = this.CautionPlayer11Btn;
                theMatch.cautionCode.goalButton = theMatch.awayGoal.GoalPlayer11Btn;
                theMatch.cautionCode.sendOffButton = theMatch.awaySendOff.SendOffPlayer11Btn;
                theMatch.cautionCode.subOffButton = theMatch.awaySubOff.SubOffPlayer11Btn;
            }

            //Carry out the actual caution by calling
            //the method to display the Caution Code screen
            cautionPlayer();
        }

        //This method is run when the 'Cancel' button is clicked
        private void CancelButton_Click(object sender, EventArgs e)
        {
            //Hide this screen to display the main Match screen
            this.Visible = false;
        }
    }
}